//
//  SKUDetailReceiveTB.m
//  ZITHER
//
//  Created by weixin on 2018/8/17.
//  Copyright © 2018年 weixn. All rights reserved.
//

#import "SKUDetailReceiveTB.h"
#import "SKUDetailReceiveTBCell.h"
#import "SKU_DetailTakeinDefault_Cell_WX.h"
@implementation SKUDetailReceiveTB

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.page = 0;
        self.delegate = self;
        self.dataSource = self;
        self.separatorStyle = UITableViewCellSeparatorStyleNone;
        self.rowHeight = UITableViewAutomaticDimension;
        self.estimatedRowHeight = 100;
        [self registerNib:[UINib nibWithNibName:@"SKUDetailReceiveTBCell" bundle:nil] forCellReuseIdentifier:@"SKUDetailReceiveTBCell"];
        [self registerNib:[UINib nibWithNibName:@"SKU_DetailTakeinDefault_Cell_WX" bundle:nil] forCellReuseIdentifier:@"SKU_DetailTakeinDefault_Cell_WX"];

        
    }
    return self;
}


#pragma MARK - 数据源
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.arrM.count;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    if ([self.indexType isEqualToString:@"2"]) {
        return [self getSKU_DetailTakeinDefault_Cell_WX:indexPath];
    }
    static NSString *sectionCell = @"SKUDetailReceiveTBCell";
    SKUDetailReceiveTBCell *cell = [tableView dequeueReusableCellWithIdentifier:sectionCell];
    if (cell == nil) {
        cell = [[SKUDetailReceiveTBCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:sectionCell];
    }
    cell.goodid = self.goodid;
    cell.IsEnquiry = self.IsEnquiry;
    cell.idnexCell = indexPath;
    cell.selectionStyle = UITableViewCellSeparatorStyleNone;
    [cell setBlockChangeIsEnquiry:^{
        self.IsEnquiry = NO;
        if (self.blockRefreshData) {
            self.blockRefreshData();
        }
    }];
    
    [cell setBlockRemoveCell:^(NSIndexPath* index) {
        
        NSIndexPath *currentIndexPath = [self indexPathForCell:cell];

        [self.arrM removeObjectAtIndex:currentIndexPath.row];
        // 再删除cell
        [self beginUpdates];
        [self deleteRowsAtIndexPaths:@[currentIndexPath] withRowAnimation:UITableViewRowAnimationFade];
        [self endUpdates];

    }];
        
    if ([self.indexType isEqualToString:@"0"]) {
        cell.typeCell = YES;
        cell.price.hidden = YES;
        cell.notiInterest.hidden = YES;
    }else if([self.indexType isEqualToString:@"1"]){
        cell.typeCell = YES;
    }else if([self.indexType isEqualToString:@"2"]){
        cell.typeCell = NO;
        cell.price.hidden = YES;
        cell.notiInterest.hidden = YES;
    }else{
        cell.typeCell = YES;
        cell.price.hidden = NO;
        cell.notiInterest.hidden = YES;
    }
    cell.indexType = self.indexType;
    id model = self.arrM[indexPath.row];
    
    if ([model isKindOfClass:[OpenGoodsSourceInfoModel class]]) {
        cell.model = model;
    }else{
        cell.modelAccept = model;
    }
    

   

    return cell;
}


-(SKU_DetailTakeinDefault_Cell_WX*)getSKU_DetailTakeinDefault_Cell_WX:(NSIndexPath *)indexPath{
    static NSString *sectionCell = @"SKU_DetailTakeinDefault_Cell_WX";
    SKU_DetailTakeinDefault_Cell_WX *cell = [self dequeueReusableCellWithIdentifier:sectionCell];
    if (cell == nil) {
        cell = [[SKU_DetailTakeinDefault_Cell_WX alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:sectionCell];
    }
    cell.selectionStyle = UITableViewCellSeparatorStyleNone;
    
    if ([self.indexType isEqualToString:@"2"]) {
        cell.type = 1;
    }
    
    id model = self.arrM[indexPath.row];
    
    if ([model isKindOfClass:[OpenGoodsSourceInfoModel class]]) {
        cell.opMpdel = model;
        cell.IsEnquiry = self.IsEnquiry;
        cell.goodid = self.goodid;
    }else{
//        cell.modelAccept = model;
    }
    return cell;
}

-(void)setIndexType:(NSString *)indexType{
    _indexType = indexType;

}




- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    [tableView deselectRowAtIndexPath:indexPath animated:NO];
    
}


-(void)setArrM:(NSMutableArray *)arrM{
    _arrM = arrM;
    
    [self reloadData];
}
-(void)setIsEnquiry:(BOOL)IsEnquiry{
    _IsEnquiry = IsEnquiry;
    [self reloadData];
    NSLog(@"");
}
@end
